package com.easyaop.api.join;

import com.easyaop.commons.utils.PointcutUtils;

import java.lang.reflect.Method;

public class JoinPoint extends AbstractJoinPoint {
    private final ClassLoader classLoader;

    private final String signature;

    public JoinPoint(ClassLoader classLoader, String signature) {
        this.classLoader = classLoader;
        this.signature = signature;
    }

    public static JoinPoint of(Class<?> clazz, String signature) {
        return new JoinPoint(clazz.getClassLoader(), signature);
    }

    public static JoinPoint of(Method method) {
        Class<?> declaringClass = method.getDeclaringClass();
        return JoinPoint.of(declaringClass, PointcutUtils.getSignature(method));
    }

    public Method getJavaMethod() {
        return getMethod(classLoader, signature);
    }

    public String getSignature() {
        return signature;
    }
}
